var ctxPath = "/yyb";

$(function() {
	$("#logout").bind("click", function() {
		var url = ctxPath + "/sys/user/logout.do";
		var data = {};
		doPostReq(url, data, function(rsp) {
			location.href = ctxPath + "/initLoginPage.do";
		});
	});
	
	$("#logoutA").bind("click", function() {
		var url = ctxPath + "/sys/user/logout.do";
		var data = {};
		doPostReq(url, data, function(rsp) {
			location.href = ctxPath + "/initAdminLoginPage.do";
		});
	});
	
	$("#download").bind("click", function() {
		window.location.href = ctxPath + "/sys/user/download.do";
	});
	
	var url = ctxPath + "/sys/notice/queryTheNotice.do";
	var data = {};
	doPostReq(url, data, function(rsp) {
		if($("#noticeContent").length > 0) {
			var retData = rsp.retData;
			if(retData != null) {
				var content = retData.content;
				$("#noticeContent").append(content);
				$("#noticeContent").show();
			}
		}
	});
});

/**
 * ajax异步请求发送Post请求至服务端的工具方法
 * @param url 请求地址
 * @param data 请求参数
 * @param callback 回调函数
 * @param beforeSendMsg 请求之前提示语,如果传递的空字符串或者不传那就不提示
 */
function doPostReq(url, data, callback) {
	$.ajax({
		type : "POST",
		url : url,
		data : data,
		dataType : "json",
		success : function(rsp) {
			var retCode = rsp.retCode;
			if("SUCCESS" == retCode) {
				callback(rsp);
			} else{
				 alert(retCode);
			}
		},
		error : function() {
			alert("通信异常");
		}
	});
}

/**
 * ajax异步请求发送Get请求至服务端的工具方法
 * @param url 请求地址
 * @param data 请求参数
 * @param callback 回调函数
 * @param beforeSendMsg 请求之前提示语,如果传递的空字符串或者不传那就不提示
 */
function doGetReq(url, data, callback) {
	$.ajax({
		type : "GET",
		url : url,
		data : data,
		dataType : "json",
		success : function(rsp) {
			var retCode = rsp.retCode;
			if("SUCCESS" == retCode) {
				callback(rsp);
			} else{
				 alert(retCode);
			}
		},
		error : function() {
			alert("通信异常");
		}
	});
}

/**
 * 解析浏览器url，获取其中的参数
 * @param name
 * @returns
 */
function getLocationString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null) {
    	return  unescape(r[2]);
    }
    return null;
}

function getShopSiteName(shopSite) {
	if("1"==shopSite) {
		return "日本亚马逊";
	} else if("2"==shopSite){
		return "6pm";
	} else if("3"==shopSite){
		return "日本乐天";	
	} else if("4"==shopSite){
		return "乐天国际";	
	} else if("5"==shopSite){
		return "中国亚马逊";	
	} else if("6"==shopSite){
		return "新版日本亚马逊";	
	} else {
		return "";
	}
}

